uni.addInterceptor('request', {
	invoke(opt) {
		opt.url = '/api' + opt.url
		opt.header = {
			'content-type': 'application/json;charset=utf-8',
			'userToken': uni.getStorageSync('userToken')
		}
	}
})

function get(url, data) {
	data = JSON.stringify(data)
	return new Promise((resolve, reject) => {
		uni.request({
			url,
			data,
			type: 'GET',
			success(res) {
				resolve(res.data)
			},
			fail(err) {
				reject(err)
			}
		})
	})

}

function Delete(url, data) {
	data = JSON.stringify(data)
	return new Promise((resolve, reject) => {
		uni.request({
			url,
			data,
			method: 'DELETE',
			success(res) {
				resolve(res.data)
			},
			fail(err) {
				reject(err)
			}
		})
	})
}

function post(url, data) {
	data = JSON.stringify(data)
	return new Promise((resolve, reject) => {
		uni.request({
			url,
			data,
			method: 'POST',
			success(res) {
				resolve(res.data)
			},
			fail(err) {
				reject(err)
			}
		})
	})
}

function put(url, data) {
	data = JSON.stringify(data)
	return new Promise((resolve, reject) => {
		uni.request({
			url,
			data,
			method: 'PUT',
			success(res) {
				resolve(res.data)
			},
			fail(err) {
				reject(err)
			}
		})
	})
}

export default {
	get,
	Delete,
	post,
	put
}